package com._520it.crm.web.controller;

import com._520it.crm.domain.CarInfo;
import com._520it.crm.domain.ClientCarInfo;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.ClientCarInfoQueryObject;
import com._520it.crm.service.IClientCarInfoService;
import com._520it.crm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by 呆 on 2017/10/3.
 */
@Controller
@RequestMapping("/clientCarInfo")
public class ClientCarInfoController {
    @Autowired
    private IClientCarInfoService clientCarInfoService;
    @RequestMapping("")
    public String index(){
        return "clientCarInfo";
    }

    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(ClientCarInfoQueryObject qo){
         return clientCarInfoService.query(qo);
    }
    /**
     * 保存 保险单申请时填写的车辆信息
     * @param clientCarInfo  前台传过来的车辆信息
     * @param orderBillId 前台传过来的保单id
     * @return
     */
    @RequestMapping("saveClientCarInfo")
    @ResponseBody
    public AjaxResult saveClientCarInfo(ClientCarInfo clientCarInfo, Long orderBillId, CarInfo carInfo){
        AjaxResult result = null;
        try {
            clientCarInfoService.saveClientCarInfo(clientCarInfo,orderBillId,carInfo);
            result = new AjaxResult("保存成功");
        } catch (Exception e) {
            e.printStackTrace();
            result = new AjaxResult(false,"保存失败");
        }
        return result;
    }
    /**
     * 保存 保险单申请时填写的车辆信息
     * @param clientCarInfo  前台传过来的车辆信息
     * @return
     */
    @RequestMapping("updateClientCarInfo")
    @ResponseBody
    public AjaxResult updateClientCarInfo(ClientCarInfo clientCarInfo, CarInfo carInfo){
        AjaxResult result = null;
        try {
            clientCarInfoService.updateClientCarInfo(clientCarInfo,carInfo);
            result = new AjaxResult("保存成功");
        } catch (Exception e) {
            e.printStackTrace();
            result = new AjaxResult(false,"保存失败");
        }
        return result;
    }
    @RequestMapping("updateWithInsuranceinfo")
    @ResponseBody
    public AjaxResult updateWithInsuranceinfo(ClientCarInfo clientCarInfo){
        AjaxResult result = null;
        try {
            /*clientCarInfoService.updateWithInsuranceinfo(clientCarInfo);*/
            result = new AjaxResult("保存成功");
        } catch (Exception e) {
            e.printStackTrace();
            result = new AjaxResult(false,"保存失败");
        }
        return result;
    }
}
